package cfluo.test.promotion;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.junit.BeforeClass;
import org.junit.Test;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.StatelessKieSession;

import cfluo.test.fact.promotion.Customer;
import cfluo.test.fact.promotion.CustomerProRange;
import cfluo.test.fact.promotion.ProdRange;
import cfluo.test.fact.promotion.ProductItem;
import cfluo.test.fact.promotion.PromotionOutput;
import util.KnowledgeSessionHelper;

public class MyTest1 {
	static KieContainer kieContainer;
	StatelessKieSession sessionStateless = null;
	KieSession sessionStatefull = null;

	@BeforeClass
	public static void beforeClass() {
		kieContainer = KnowledgeSessionHelper.createRuleBase();
	}
	@Test
	public void testPromotion1(){
		 sessionStatefull = KnowledgeSessionHelper
	                .getStatefulKnowledgeSession(kieContainer, "mytest1-session");
		 Customer customer = new Customer();
		 customer.setIsVip(true);
		 ProductItem productItem = new ProductItem();
		 productItem.setProdName("测试商品1");
		 productItem.setPrice(200d);
		 productItem.setProdCode("00001");
		 ProductItem productItem2 = new ProductItem();
		 productItem2.setProdName("测试商品XX");
		 productItem2.setPrice(100d);
		 productItem2.setProdCode("00008");
		 ProductItem productItem3 = new ProductItem();
		 productItem3.setProdName("测试商品3");
		 productItem3.setPrice(160d);
		 productItem3.setProdCode("00003");
		 ProdRange customerProRange = new ProdRange();
		 PromotionOutput promotionOutput=new PromotionOutput();
		 sessionStatefull.setGlobal("promotionOutput", promotionOutput);
		 sessionStatefull.insert(customerProRange);
		 sessionStatefull.insert(customer);
		 sessionStatefull.insert(productItem);
		 sessionStatefull.insert(productItem2);
		 sessionStatefull.insert(productItem3);
		 sessionStatefull.fireAllRules();
		 sessionStatefull.dispose();
		/* List<ProductItem> list = promotionOutput.getList();
		 System.out.println("最终的总价为:"+promotionOutput.getTotalCost());
		 System.out.println("促销明细:");
		 for (ProductItem prod : list) {
			System.out.println("商品名称:"+prod.getProdName()+" 商品编码:"+prod.getProdCode()+" 商品单价："+prod.getPrice()+" 促销价格:"+prod.getPromotionPrice());
		}*/
	}
}
